{include file="styles/header.tpl"}
<link rel="stylesheet" media="screen,projection" type="text/css" href="{$smarty.const.HOST_STATIC}/admin/css/dragontool.fix.css" />
<div id="content" class="box"
	 {include file="forecast/index.windows.resize.tpl"}	>
	<h1>Validate Forecast</h1>
		<div class="forcasts-condiction">
		 {include file="forecast/index.condition.tpl"}
		</div>
	<div class ="forcasts-btn-confirm">
		<h2>
			{$intTotal} record{if $intTotal>2}s{/if}
			{if ($AppUI->admin_group_id==$smarty.const.GROUP_Administrator || $AppUI->admin_group_id==$smarty.const.GROUP_Inventory) }
				<input type="button" class="bt" value="Confirm" onclick="do_confirm();" />
			{/if}
		</h2>
	</div>
	<div class="forcasts-color" >
		  {include file="forecast/index.color.tpl"}
	</div>
	<div class="clearfix"></div>
	{include file="forecast/index.addcolumn.tpl"}
	<div class="clearfix"></div>
	<div class="data-content">
		<div class="head">
			{include file="forecast/index.result.tpl"}
		</div>
		{if $arrResult !=null}
		<div class="content">
			{include file="forecast/index.result.tpl"}
		</div>
		{/if}
	</div>
	{include file="styles/paginator.tpl"}
	<form method="get" name="frmSearch"> 
		<input type="hidden" name="is" value="{$intStatus}" />
		<input type="hidden" name="li" value="{$intItemOnPerPage}" />
	</form>
	<input type="hidden" value ="{$AppUI->admin_group_id}" id="group_value">
</div>
{literal}
<script type="text/javascript">
	function wait(id, v)
	{
		return;
		var e	= $('#w_'+id);
		var html= '<img src="img/wait.gif" />';
		if(v=='done'){
			html= '<img src="img/ok.gif" />';
		}
		e.html(html);
	}
	
	function update_field(i, f)
	{
		var v = $('.data-content .content #'+f+'_'+i).val();
		var idW	= f+'_'+i;
		wait(idW, 'wait');
		
		$.post
		(
			HOST + '/{/literal}{$strType}{literal}/update-field/',
			{
				'i'	: i,
				'f'	: f,
				'v'	: v
			},
			function(data)
			{
				var idW	= f+'_'+i;
				wait(idW, 'done');
			},
			'json'
		);
	}
	
	function update_field_checkbox(i, f)
	{
		var v = $('.data-content .content #'+f+'_'+i).attr('checked')==true?1:0;
		var idW	= f+'_'+i;
		wait(idW, 'wait');
		
		$.post
		(
			HOST + '/{/literal}{$strType}{literal}/update-field-checkbox/',
			{
				'i'	: i,
				'f'	: f,
				'v'	: v
			},
			function(data)
			{
				var idW	= f+'_'+i;
				wait(idW, 'done');
				var group = parseInt($("#group_value").val());
				if(group > 1)
				{
					if(f =='marketing_check')
					{
						$('.data-content .content #'+f+'_'+i).attr('disabled', 'true');
						$('.data-content .content #'+ 'marketing_suggest' +'_'+i).attr('disabled', 'true');
						$('.data-content .content #'+ 'marketing_reason' +'_'+i).attr('disabled', 'true');

					
					}

					if(f =='buying_check')
					{
						$('.data-content .content #'+f+'_'+i).attr('disabled', 'true');
						$('.data-content .content #'+ 'buying_suggest' +'_'+i).attr('disabled', 'true');
						$('.data-content .content #'+ 'buying_reason' +'_'+i).attr('disabled', 'true');
						$('#forecasts.sku.td_' + i).addClass('marketing-feedback-pending');
					}

					if(f =='inventory_check')
					{
						$('.data-content .content #'+f+'_'+i).attr('disabled', 'true');
						$('.data-content .content #'+ 'final_quantity' +'_'+i).attr('disabled', 'true');
					}
				}
			},
			'json'
		);
	}

	function update_field_checkboxall(f)
	{
		var v = $('.data-content #'+f+'_all').attr('checked')==true?1:0;

		checkAll(f , $('.data-content #'+f+'_all').attr('checked'));

		var idW	= f+'_all';
		wait(idW, 'wait');
		
		$.post
		(
			HOST + '/{/literal}{$strType}{literal}/update-field-checkbox-all/',
			{
				'f'	: f,
				'v'	: v
			},
			function(data)
			{
				var idW	= f+'_all';
				wait(idW, 'done');

			},
			'json'
		);

	}

	function checkAll(f, checktoggle)
	{
		$('.' + f +'_class').each (function(){
		   if(this.disabled==false){
		     this.checked = checktoggle;
		  }
		})
	}

	function do_confirm()
	{
		var msg	= 'Confirm the forecast data. Are you sure?';
		if( confirm(msg) )
		{
			window.location.href	= HOST + '/forecast/confirm';
		}
	}
	
	function do_deleteColumn(v)
	{
		var msg	= 'Remove the column ['+v+']. Are you sure?';
		if( confirm(msg) ){
			showWaiting();
			$.post
			(
				HOST_ADMIN + '/forecast/drop-column',
				{
					'c'	: v
				},
				function(data)
				{
					window.location.href = window.location.href;
				},
				'json'
			);
		}
	}

	$(document).ready(function(){
		
		loadFormToDate();

		$("#categoryCon").change(function(){
		 loadFormToDate();
		});

		$("#shipmentType").change(function(){
		 loadFormToDate();
		});
	});

	function loadFormToDate()
	{
	    var cat = $("#categoryCon").val();
		var ship = $("#shipmentType").val();
	   	$.post
			(
				HOST_ADMIN + '/forecast/change-param',
				{
					'category'	: cat,
					'ship' : ship
				},
				function(data)
				{
					$("#fromDate").val(data.fromdate);
					$("#toDate").val(data.todate);
					$("#forcastsDays").val(data.days);
				},
				'json'
			);
	}
</script>
{/literal}
<div id="currenttab" class="category_validate_last_forecast" style="display: none;">
{include file="styles/footer.tpl"}